package com.mydemo.game.resaultStage;

import com.mydemo.entity.Driver;
import com.mydemo.entity.Save;

import java.util.Scanner;

public class DriverAddDays {
    static Scanner scanner = new Scanner(System.in);
    public static final Save driverAddDays(Save save) {
        boolean flag = true;
        while (flag) {
            // 打印所有司机信息
            for (Driver driver : save.getDriverList()) {
                System.out.println("Id: " + driver.getId() + " 司机 " + driver.getName() + "，剩余天数：" + driver.getDays());
            }
            System.out.println("请选择需要续费的司机, 输入0退出");
            int choose = scanner.nextInt();
            if (choose == 0) {
                flag = false;
            } else {
                // 查找选中的司机
                Driver chosenDriver = null;
                for (Driver driver : save.getDriverList()) {
                    if (driver.getId() == choose) {
                        chosenDriver = driver;
                        break;
                    }
                }
                if (chosenDriver != null) {
                    System.out.println("该司机剩余的天数：" + chosenDriver.getDays());
                    System.out.println("请输入需要续费的天数，输入0退出");
                    int addDays = scanner.nextInt();
                    if (addDays == 0) {
                        System.out.println("退出");
                        flag = false;
                    } else {
                        // 假设司机续费的费用计算方式与车辆相同
                        int money = addDays * chosenDriver.getSalary(); // 假设司机也有rentPrise属性
                        if (money > save.getMoney()) {
                            System.out.println("金额不足，已自动退出");
                            flag = false;
                        } else {
                            save.setMoney(save.getMoney() - money);
                            chosenDriver.setDays(chosenDriver.getDays() + addDays);
                        }
                    }
                } else {
                    System.out.println("未找到指定ID的司机，请重新输入。");
                }
            }
        }
//        scanner.close();
        return save;
    }
}